package io.adrainty.bolee.framework.commons.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.io.IOException;
import java.io.Serial;

/**
 * <p>SafeToStringSerializer</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description SafeToStringSerializer
 * @since 2025/8/15 15:26:02
 */
public class SafeToStringSerializer extends ToStringSerializer {

    @Serial
    private static final long serialVersionUID = -2796686081846963523L;

    @Override
    public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        if (value == null) {
            gen.writeNull();
        } else {
            super.serialize(value, gen, provider);
        }
    }
}
